<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./../template/WorkspaceTemplate.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="top">
        
    </ui:define>

    <ui:define name="left">
       
    </ui:define>

    <ui:define name="right">
       
    </ui:define>

    <ui:define name="content">
        <h:form>
            <p:panel header="Message Information">
                <p:messages showDetail="true"/>
                <h:panelGrid columns="3">
                    <h:outputLabel value="Subject: *"/>
                    <p:inputText id="subject" required="true" requiredMessage="Subject is compulsory"
                                 value="#{msgManagerBean.newMessage.subject}"/>
                    <p:message for="subject"/>

                    <h:outputLabel value="Sender: "/>
                    <h:outputText value="#{workspaceManagerBean.currentStaff.fullName}"/>
                    <h:outputText value=""/>

                    <h:outputLabel value="Receivers: *"/>
                    <p:commandButton value="Choosing..." onclick="dlg1.show()"/>
                    <h:outputText value=""/>
                </h:panelGrid>
            </p:panel>

            <p:panel header="Message Content">
                <p:editor value="#{msgManagerBean.newMessage.content}"/>
            </p:panel>
            <p:commandButton value="Send" ajax="false" action="#{msgManagerBean.sendNewMessage}"/>
            <p:commandButton value="Back" onclick="javascript: history.go(-1)"/>
            
            <p:dialog widgetVar="dlg1"
                      header="Choose receivers..."
                      width="600" height="350" showEffect="flip" hideEffect="flip">
                <p:dataTable value="#{msgManagerBean.allUsers}" var="rcver" selection="#{msgManagerBean.selectedReceivers}"
                             style="width: 100%"
                             paginator="true" rows="5"  
                             paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                             rowsPerPageTemplate="5,10,15"
                             widgetVar="receivers">
                    <f:facet name="header">
                        <p:outputPanel>
                            <h:outputText value="Search all fields:" />
                            <h:inputText id="globalFilter" onkeyup="receivers.filter()" />
                        </p:outputPanel>
                    </f:facet>
                    
                    <p:column selectionMode="multiple" />
                    
                    <p:column headerText="Name"
                              filterBy="#{rcver.staff.fullName}">
                        <h:outputText value="#{rcver.staff.fullName}"/>
                    </p:column>
                    
                    <p:column headerText="Username"
                              filterBy="#{rcver.username}">
                        <h:outputText value="#{rcver.username}"/>
                    </p:column>
                    
                </p:dataTable>
                <p:commandButton value="OK" onclick="dlg1.hide()"/>
            </p:dialog>
        </h:form>
    </ui:define>

    <ui:define name="bottom">
       
    </ui:define>

</ui:composition>
